package com.fwj.authorization.staff.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fwj.authorization.staff.entity.SysPermission;
import com.fwj.authorization.staff.entity.SysRole;
import com.fwj.authorization.staff.mapper.SysPermissionMapper;
import com.fwj.authorization.staff.service.SysPermissionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 权限
 *
 * @author 樊温军
 * @date 2025/3/18 上午10:32
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements SysPermissionService {

    @Override
    public IPage<SysPermission> getPage(Page<SysPermission> page, SysPermission sysPermission) {
        return baseMapper.getPage(page, sysPermission);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean savePermission(List<SysPermission> sysPermissions) {
        return this.saveOrUpdateBatch(sysPermissions);
    }

    @Override
    public List<SysRole> getRoleListByPermissionUrl(String permissionUrl) {
        List<SysRole> list = baseMapper.getRoleListByPermissionUrl(permissionUrl);
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        return list;
    }
}
